package com.basker.pisces.domain.value;

import java.util.Collections;
import java.util.List;

import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSON;

/**
 * 封装了一个只读List的值对象
 *
 * @author hangwen
 */
public class ListValue implements IValueObject {

    public static final ListValue EMPTY = new ListValue(Collections.emptyList());

    private List<Object> list;

    public ListValue(List<Object> list) {
        if (list == null) {
            list = Collections.emptyList();
        }

        this.list = Collections.unmodifiableList(list);
    }

    @Override
    public Object getDataValue() {
        return list;
    }

    @Override
    public String getPresentValue() {
        return JSON.toJSONString(this.list);
    }

    @Override
    public boolean isEmpty() {
        return CollectionUtils.isEmpty(list);
    }

}
